<template>
  <a-spin :spinning="spinning">
    <a-alert message="点击`开始考试`后将自动进入考试，请诚信考试！"
             type="error"
             show-icon
             style="width: 90%;  margin-left: 5%;margin-right: 5%; margin-top: 1%"
             closable
             @close="onClose"/>
    <a-card title="考试基本信息" style="width: 90%; height: 50%; margin-left: 5%;margin-right: 5%; margin-top: 1%">
      <!--    <template #extra><a href="#">more</a></template>-->
      <p><b>考试名称：</b>{{ paramData.title }}</p>
      <p><b>考试时长：</b>{{ paramData.totalTime }}</p>
      <p><b>试卷总分：</b>{{ paramData.totalScore }}</p>
      <p><b>及格分数：</b>{{ paramData.qualifyScore }}</p>
      <p><b>考试描述：</b>{{ paramData.content }}</p>
      <p><b>开放类型：</b>{{ paramData.openType }}</p>
    </a-card>
    <br/>
    <a-button type="primary" shape="round" :size="size" style="margin-left: 5%;" @click="handleCreate">
      <template #icon>
        <play-circle-outlined/>
      </template>
      开始考试
    </a-button>
    <a-button shape="round" :size="size" style="margin-left: 1%;" @click="returnClick">
      返回
    </a-button>
  </a-spin>
</template>
<script>

import {ref} from 'vue';
import router from "@/route";
import {useRoute} from 'vue-router';
import {createPaper, fetchDetail} from "@/api/module/exam";

export default {
  components: {},
  data() {
    return {}
  },
  setup() {
    const routers = useRoute();
    let detailData = {};
    const paramData = JSON.parse(routers.query.id);
    const spinning = ref(false);
    let postForms = {
      id: ''
    };
    let postForm = {
      examId: '',
    };
    const onClose = e => {
      console.log(e, 'I was closed.');
    };
    const returnClick = e => {
      router.push("/paper/exam/list");
    };
    const handleCreate = e => {
      spinning.value = !spinning.value;
      postForms.id = paramData.id
      postForm.examId = paramData.id
      fetchDetail(postForms).then(response => {
        detailData = response.data
      })
      createPaper(postForm).then(response => {
        console.log(response)
        if (response.code === 200) {
          console.log("response id+++" , response.data.id)
          setTimeout(function () {
            router.push({
              path: '/exam/exam',
              query: {
                id: JSON.stringify(response.data.id)
              }
            })
            spinning.value = !spinning.value;
          }, 1000)
        }
      }).catch(() => {
        this.loading = false
      })
    };
    return {
      onClose,
      returnClick,
      handleCreate,
      postForms,
      postForm,
      paramData,
      detailData,
      spinning,
    };
  }
};
</script>
<style lang="less" scoped>
</style>
